package com.iweb.controller;

import cn.hutool.core.util.StrUtil;
import com.iweb.resp.R;
import com.iweb.utils.CodeUtil;
import com.sun.org.apache.regexp.internal.RE;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;

@CrossOrigin(allowCredentials = "true")
@RestController
@RequiredArgsConstructor
public class SysController {

    final private RedisTemplate<String, Object> redisTemplate;

    @PostMapping("generateCode")
    public R<String> generateCode() {
        String code = CodeUtil.generateCode(5);
        // 保存 redis  60s
        redisTemplate.opsForValue().set("code::" + code, "1", Duration.ofSeconds(60));
        return R.success("generate code", code);
    }

}
